package com.jt.common.util;

import java.util.List;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.jt.common.pageinfo.PageInfoVo;

/**
 * @Author: Jingyan
 * @Time: 2018-05-08 14:42
 * @Description:
 */
public class PageInfoUtil {

    /**
     * Created with Jingyan
     * Time: 2018-05-08 14:51
     * Description: PageInfo 转换 PageInfoVo，减少依赖
     */
    public static <T> PageInfoVo<T> getPageInfo(PageInfo<T> pageInfo) {
        PageInfoVo<T> pageInfoVo = new PageInfoVo<>();
        pageInfoVo.setPages(pageInfo.getPages());
        pageInfoVo.setPageSize(pageInfo.getSize());
        pageInfoVo.setPageNum(pageInfo.getPageNum());
        pageInfoVo.setTotal(pageInfo.getTotal());
        pageInfoVo.setList(pageInfo.getList());
        return pageInfoVo;
    }

    public static <T> PageInfo<T> toPageInfo(List<T> result){
		if(!(result instanceof Page)){
			throw new IllegalArgumentException("result must instance of Page.");
		}
		PageInfo<T> pagination = new PageInfo<T>(result,1);
		return pagination;
	}
	public static <T> Pagination<T> toPagination(PageInfo<T> pageInfo){
		return new Pagination<T>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getPages(), pageInfo.getTotal(), pageInfo.getList());
	}

	public static <T> Pagination<T> toPagination(int pageNum,int pageSize,int pages,long total,List<T> list){
		return new Pagination<T>(pageNum, pageSize, pages, total, list);
	}


}